// pages/myself/commission/ActuallyAchieve.js
var Zan = require('../../../dist/index.js');
let network = null;
let utils = null;
let api = null;
const app = getApp();
var start = 0;
Page(Object.assign({}, Zan.TopTips, {

  /**
   * 页面的初始数据
   */
  data: {
    income2: 0,
    commisshouyi: [],
    recordsTotal: 0,
    nodata: {
      msg: '没有数据',
      notype: 2,
      imgurl: '../../../images/nodatas.png',
      nourl: ''
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    network = new app.NetWorkUtils();
    utils = new app.Utils();
    api = new app.Api();

    this.onPullDownRefresh();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    start = 0;
    wx.stopPullDownRefresh();
    this.setData({
      commisshouyi: []
    });
    network._post_page_json(this, api.Usereain, start, {}, sjsuccess);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // if (this.data.commisshouyi.length < this.data.recordsTotal) {
    //   start = start + 20;
    //   network._post_page_json(this, api.Usereain, start, {}, sjsuccess);
    // }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  // tixianSq: function (e) {
  //   if (app.globalData.userAndTenantInfo.mobile) {
  //     wx.navigateTo({
  //       url: '/pages/myself/commission/commtixian',
  //     })
  //   } else {
  //     wx.showModal({
  //       title: '提示',
  //       content: '还未绑定手机号，请绑定手机号',
  //       success: function (res) {
  //         if (res.confirm) {
  //           wx.navigateTo({
  //             url: '/pages/myself/info/bindMobile',
  //           })
  //         } else if (res.cancel) {
  //           console.log('用户点击取消')
  //         }
  //       }
  //     })
  //   }

  // }
}))

var sjsuccess = function (that, res) {
  if (res.data.data) {
    var commis = res.data.data.data;
    for(var i = 0; i < commis.length; i++){
      commis[i].create_time = utils.formatDate(new Date(commis[i].create_time));
      commis[i].earnings = Math.round((commis[i].total / 100) * (commis[i].proportion / 100) * 100) / 100;
    }

    that.setData({
      income2: res.data.data.shijimoney,
      commisshouyi: that.data.commisshouyi.concat(commis),
      recordsTotal: res.data.data.data.length
    })
  }
}
